package conservare.web.converter;


import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;



@FacesConverter("EnumConverter") 
public class EnumConverter implements Converter{
	@SuppressWarnings("unchecked")
	public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
			@SuppressWarnings("rawtypes")
			Class enumType = component.getValueExpression("value").getType(context.getELContext());
			
			return Enum.valueOf(enumType, value);
	}
	
	public String getAsString(FacesContext context,	UIComponent component, Object object) throws ConverterException {
		if (object == null) {
			return null;
		}
		@SuppressWarnings("rawtypes")
		Enum type = (Enum) object;
		
		return type.toString();
	}
	
	
}
